#include <graphics.h>
#include <math.h>
#include <iostream.h>

class rocket
 {    public:
      float m0;
      float dm;
      float x;
      float y;
      float vx;
      float vy;
      float vp;
      float t;
      float vx1;
      float vy1;
      float u;
      float g;
      public:    
        void cycle(void)
        {
                float dt=0.001;
                g=9.8;
                if ((m0-(dm *t))>10) {vp=(dt)*(u*dm /(m0-(dm *t))-g);}
                else {vp=-g*dt;}
                moveto(100*t,0.01*y);
                vy1=vy+vp;
                y=y-(vy1*t)+((u*dm /(m0-(dm *t))-g))*(t*t/2);
                
                //vx1=vx;
                //x=x+vx1*(t);
                //if ((m0-(dm * t))>10){y=y+vy1*t-(u*dm /(m0-(dm *t))-g)*t*t/2;}
                //else {y=y+g*t*t/2-vy1*t ;}
                
                t=t+dt;
                lineto(100*t,0.01*y);
                t=t-dt;
                if ((m0-(dm *t))>10){
                moveto(100*t,10-(m0-(dm *100*t)));}
                else {moveto(100*t,100);}
                t=t+dt;
                if ((m0-(dm *t))>10){
                lineto(100*t,10-(m0-(dm *100*t)));}
                else {lineto(100*t,100);}
                t=t-dt;
                if ((m0-(dm *t))>10){
                moveto(100*t,240-(u*dm /(m0-(dm *t))+g)/2);}
                else {moveto(100*t,240+g/2);}
                t=t+dt;
                if ((m0-(dm *t))>10){
                lineto(100*t,240-(u*dm /(m0-(dm *t))+g)/2);}
                else {lineto(100*t,240+g/2);}
                vy=vy1;
                //vx=vx1;
                cout<<" x="<<x<<" y="<<y <<" vy="<< vy <<" m=" << (m0-(dm *t))-10<<" t=" << t <<" yp="<< vy1*t <<endl;
                if ((m0-(dm *t))>10) {cout << u*dm /(m0-(dm *t))-g;}
                else {cout << -g;}
        }  

        rocket(void)
        {
            m0=0;
      	    dm=0;
      	    x=0;
            y=0;
            vx=0;
            vy=0;
            vp=0;
        }  

        ~rocket(void)
        {
            m0=0;
      	    dm=0;
      	    x=0;
            y=0;
            vx=0;
            vy=0;
            vp=0;
        }  
        rocket(float m0a, float dma, float xa,float ya, float vxa, float vya)
        {
          m0=m0a;
          dm=dma;
          u=xa;
          //x=(int)xa;
          y=(int)ya;
          vx=vxa;
          vy=vya;
          t=0;
          x=0;
          //u=6000;
        }
  };

int main()    
{   float a=18.0,b=3.0,c=6000.0,d=2400.0,e=0.0,f=0.0;
    int n=1;
    cout << "mass of fuel(11):";
    cin >> a;
    cout << endl;
    cout << "mass flow rate(3):";
    cin >> b;
    cout << endl;
    cout << "gas velocity(240):";
    cin >> c;
    cout << endl;
    initwindow(640,480);
    moveto(637,240);
    lineto(3,240);
    moveto(3,477);
    lineto(3,3);
    outtextxy(5,5,"y, m");
    outtextxy(600,236,"t, c");
    while (n<60) { moveto(3,240 + n*10); lineto(6,240+n*10);
    //outtextxy(8,240+n*10,(char*)n);
    moveto(3,240 - n*10); lineto(6,240-n*10);
    moveto(n*10,238); lineto(n*10,242);
    n++;}
    rocket rock(a,b,c,24000,0,0);
    while (rock.y<48000) {rock.cycle();
     //getch();
     }
    getch();
    closegraph();
    return 0;
}
